<template>
  <div class="bg_box">
    <el-form
      ref="ruleForm"
      :model="ruleForm"
      status-icon
      :rules="rules"
      label-width="80px"
      class="login-ruleForm"
      hide-required-asterisk
      :show-message="false"
    >
      <div class="title">医卫融合系统</div>
      <el-form-item label="用户名" prop="userName" class="username">
        <el-input
          v-model="ruleForm.userName"
          type="text"
          placeholder="请输入登录账号"
        ></el-input>
        <!-- <input type="text" v-model="ruleForm.username"> -->
      </el-form-item>
      <el-form-item label="密码" prop="passWord">
        <el-input
          v-model="ruleForm.passWord"
          type="password"
          autocomplete="off"
          placeholder="请输入登录密码"
        ></el-input>
      </el-form-item>
      <el-form-item class="subBtn">
        <el-button
          type="primary"
          @keydown.native="loginIn"
          @click="submitForm('ruleForm')"
          >登 录</el-button
        >
        <el-button type="primary" @click="submitSign('ruleForm')"
          >注 册</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "",
  components: {},
  data() {
    return {
      ruleForm: {
        userName: "",
        passWord: "",
      },
      rules: {
        userName: { required: true, message: "请输入用户名", trigger: "blur" },
        passWord: { required: true, message: "请输入密码", trigger: "blur" },
      },
    };
  },
  computed: {},
  watch: {},
  created() {
    document.addEventListener("keydown", this.loginIn);
  },
  mounted() {},
  methods: {
    submitForm() {
      this.$refs.ruleForm.validate((vaild) => {
        let params = {
          ...this.ruleForm,
        };
        this.$store.dispatch("Login", params).then((res) => {
          this.$router.push({ path: "/home" });
          document.removeEventListener('keydown', this.loginIn)
        });
      });
    },
    loginIn(e) {
      if (e.key === "Enter") {
        this.submitForm();
      }
    },
    submitSign() {
      // let params = {
      //   ...this.ruleForm
      // }
      // signUp(params)
    },
  },
};
</script>

<style scoped lang="less">
.bg_box {
  height: 100%;
  width: 100%;
  background-image: url("~@/assets/image/bg.jpg");
  background-size: cover;
  background-repeat: no-repeat;
  overflow: hidden;
  .login-ruleForm {
    width: 400px;
    margin-top: 240px;
    background-color: rgba(255, 255, 255, 0.2);
    padding: 20px;
    position: absolute;
    right: 160px;
    top: initial;
    border-radius: 5px;
    .title {
      margin-bottom: 15px;
      text-align: center;
      font-size: 20px;
      font-weight: bold;
      color: #000;
      letter-spacing: 2px;
    }
    ::v-deep .el-form-item__label {
      color: #fff;
    }
    .subBtn {
      margin-bottom: 10px;
      ::v-deep .el-form-item__content {
        .el-button {
        }
      }
    }
  }
}
</style>
